﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO_HealthInsurance;
namespace DAO_HealthInsurance
{
  public  class DAOPolicyRequest:ConnectDatabase
    {
        public SqlCommand Cmd;
        public DTOPolicyRequestDetail objPoRe;
        public DataTable ListPoRe()
        {
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("ListPoRe", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("PolicyRequestDetails");
                da.Fill(dt);
                CloseConnect();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public int InsertPoRe(DTOPolicyRequestDetail objPoRe)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("InsertPoRe", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@RequestDate", SqlDbType.DateTime).Value = objPoRe.RequestDate;
                Cmd.Parameters.Add("@EmpNo", SqlDbType.Int).Value = objPoRe.EmpNo;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoRe.PolicyId;
                Cmd.Parameters.Add("@PolicyName", SqlDbType.VarChar,50).Value = objPoRe.PolicyName;
                Cmd.Parameters.Add("@PolicyAmount", SqlDbType.Float).Value = objPoRe.PolicyAmount;
                Cmd.Parameters.Add("@Emi",SqlDbType.Float).Value = objPoRe.PolicyEmi;
                Cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = objPoRe.CompanyId;
                Cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar,50).Value = objPoRe.CompanyName;
                Cmd.Parameters.Add("@Status", SqlDbType.VarChar, 50).Value = objPoRe.Status;
            

                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;
        }

        public int DeletePoRe(DTOPolicyRequestDetail objPoRe)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("DeletePoRe", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@RequestId", SqlDbType.Int).Value = objPoRe.RequestId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }
        public int UpdatePoRe(DTOPolicyRequestDetail objPoRe)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("UpdatePoRe", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@RequestId", SqlDbType.Int).Value = objPoRe.RequestId;
                Cmd.Parameters.Add("@RequestDate", SqlDbType.DateTime).Value = objPoRe.RequestDate;
                Cmd.Parameters.Add("@EmpNo", SqlDbType.Int).Value = objPoRe.EmpNo;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoRe.PolicyId;
                Cmd.Parameters.Add("@PolicyName", SqlDbType.VarChar, 50).Value = objPoRe.PolicyName;
                Cmd.Parameters.Add("@PolicyAmount", SqlDbType.Float).Value = objPoRe.PolicyAmount;
                Cmd.Parameters.Add("@Emi", SqlDbType.Float).Value = objPoRe.PolicyEmi;
                Cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = objPoRe.CompanyId;
                Cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50).Value = objPoRe.CompanyName;
                Cmd.Parameters.Add("@Status", SqlDbType.VarChar, 50).Value = objPoRe.Status;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }

        public DataTable GetPoReByReId(DTOPolicyRequestDetail objPoRe)
        {
            try
            {
                Cmd = new SqlCommand("GetPoReByReId", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@RequestId", SqlDbType.Int).Value = objPoRe.RequestId;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("PolicyRequestDetails");
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
